package com.lanou.beautifulwardrobe.Home.Adapter;

import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.Response;
import com.lanou.beautifulwardrobe.R;
import com.lanou.beautifulwardrobe.contants.VolleySingleton;
import com.lanou.beautifulwardrobe.entify.ShowProducts;

import java.util.List;

/**
 * Created by dllo on 15/11/2.
 */
public class HomeWaterItemAdapter extends RecyclerView.Adapter<HomeWaterItemAdapter.WaterItemViewHolder> {

    private List<ShowProducts> datas;
    private VolleySingleton volleySingleton = VolleySingleton.getInstance();

    public void addData(List<ShowProducts> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public WaterItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.showproducts, null);
        return new WaterItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final WaterItemViewHolder holder, int position) {
        if (datas != null && datas.size() > 0) {
            ShowProducts products = datas.get(position);
            holder.showProductPriceTv.setText(products.getTaobao_selling_price());
            Log.i("lanou",products.getTaobao_selling_price());
            volleySingleton.getImageResuest(products.getTaobao_pic_url(), new Response.Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    holder.showProductIv.setImageBitmap(response);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    class WaterItemViewHolder extends RecyclerView.ViewHolder {
        private ImageView showProductIv;
        private TextView showProductPriceTv;

        public WaterItemViewHolder(View view) {
            super(view);
            showProductIv = (ImageView) view.findViewById(R.id.showProductIv);
            showProductPriceTv = (TextView) view.findViewById(R.id.showProductPriceTv);

        }
    }
}
